# package
# __init__.py
from create import User, session
from sqlalchemy import and_, or_

# ret = session.query(User).filter_by(name='alex').all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(User.id > 1, User.name == 'eric').all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(User.id.between(10, 13), User.name == 'eric').all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(User.id.in_([1, 3, 4, 8, 10])).all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(~User.id.in_([1, 4, 8, 10])).all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(User.id.in_(session.query(User.id).filter_by(name='eric'))).all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(and_(User.id > 3, User.name == 'eric')).all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

# ret = session.query(User).filter(or_(User.id < 8, User.name == 'eric')).all()
# for item in ret:
#     print("%d %s %s" %(item.id, item.name, item.extra))

ret = session.query(User).filter(
    or_(
        User.id < 2,
        and_(User.name == 'eric', User.id > 3),
        User.extra != ''
    )
).all()
for item in ret:
    print("%d %s %s" %(item.id, item.name, item.extra))